<?php
/*
Plugin Name: BPDEV-SIMPLEPIE LOADER
Plugin URI: http://bp-dev.org/projects/#aggregator
Description: This script load <a href="http://simplepie.org">SimplePie</a> library to parse feed.
Author: Nicola Greco
Version: 0.3
Author URI: http://nicolagreco.com

LICENSE FOR THIS SCRIPT, SIMPLEPIE IS NOT INCLUDED IN THIS LICENSE, LOOK INTO bpdev-simplepie/LICENSE.txt FOR ITS LICENSE

Copyright (c) 2009-2011, Nicola Greco (mail: notsecurity@gmail.com | website: http://nicolagreco.com).

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

define( 'BPDEV_SIMPLEPIE_NAME', 'BPDEV-SIMPLEPIE' );
define( 'BPDEV_SIMPLEPIE_VERSION', '0.3' );
define( 'SIMPLEPIE_VERSION', '1.1.3' );

require_once( 'bp-core.php' );
require_once( 'bpdev-core.php' );

add_action( 'init', 'bpdev_simplepie_setup_globals', 1 );
add_action( '_admin_menu', 'bpdev_simplepie_setup_globals', 1 );

add_action( 'bpdev_admin_plugins_screen', 'bpdev_simplepie_admin_menu_screen', 3 );
add_action( 'bpdev_admin_plugins_save', 'bpdev_simplepie_admin_menu_save', 3 );

if ( !get_option( 'bpdev-simplepie-status' ) ) add_option( 'bpdev-simplepie-status' , 'off' );

function bpdev_simplepie_setup_globals() {

	global $bp;
	$bp->bpdev->simplepie->slug = 'simplepie';
	$bp->bpdev->simplepie->src = 'bpdev-simplepie/simplepie.inc';

}

function bpdev_simplepie_admin_menu_save() {

	do_action( 'bpdev_admin_save_component', 'bpdev-simplepie-status' );

}
function bpdev_simplepie_admin_menu_screen() {

	?>
	<h3>BPDEV-SIMPLEPIE</h3>
	<table class="form-table">

		<tr valign="top">

			<th scope="row">Plugin Version</th>

			<td>
				<?php echo BPDEV_SIMPLEPIE_VERSION; ?>
			</td>

		</tr>

		<tr>

			<th scope="row">SimplePie Version</th>

			<td>
				<?php echo SIMPLEPIE_VERSION; ?>
			</td>

		</tr>

		<tr>

			<th scope="row">Plugin Status</th>

			<td>
				<select id="bpdev-simplepie-status" name="bpdev-simplepie-status">

					<option value="off"  <?php if ( get_option( 'bpdev-simplepie-status' ) == "off" || !get_option( 'bpdev-simplepie-status' ) ) echo 'selected=""'; ?>>Off</option>

					<option value="on" <?php if ( get_option('bpdev-simplepie-status') == "on") echo 'selected=""'; ?>>On</option>

				</select>
			</td>

		</tr>

	</table>
	<?php
}

function simplepie_init()  {

	global $bp;

	if ( !get_option( 'bpdev-simplepie-status' ) || get_option( 'bpdev-simplepie-status' ) == "on" ) {

		if ( file_exists( $bp->bpdev->simplepie->src ) && isset( $bp->bpdev->simplepie->src ) )
			include_once( $bp->bpdev->simplepie->src );
		else
			include_once( 'bpdev-simplepie/simplepie.inc' );

	}

}
?>
